<?php

/**
 * Description of HttpCodeException
 *
 * @author dan
 */
class HttpCodeException extends LogicException {

    const BAD_REQUEST = 400;
    const PAGE_NOT_FOUND = 404;
    const UNAUTHORIZED = 401;
    const FORBIDDEN = 403;
    const UNSUPPORTED_METHOD = 405;
    const SERVER_ERROR = 500;
    const UNKNOWN = 0;

    public function __construct($code = 0, $previous = null) {

        $messages[400] = 'HTTP/1.0 400 Bad Request';
        $messages[401] = "HTTP/1.0 401 Unauthorized";
        $messages[403] = 'HTTP/1.0 403 Forbidden';
        $messages[404] = "HTTP/1.0 404 Not Found";
        $messages[405] = "HTTP/1.0 405 Method Not Allowed";
        $messages[500] = "HTTP/1.0 500 Server Error";

        if (array_key_exists($code, $messages)) {
            $message = $messages[$code];
        } else {
            $message = $messages[self::SERVER_ERROR];
        }


        parent::__construct($message, $code, $previous);
    }

}